package com.analyse.stock.form;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;
import java.util.Set;

@Data
public class PickStockQueryForm implements Serializable {
    private String stockCode;
    /**
     * 行业板块codes
     **/
    private Set<String> boardCodes;

    /**
     * 换手率> N%
     **/
    private BigDecimal exchangeRate;

    /**
     * > 最小流通市值(千万元)
     **/
    private BigDecimal minTradeMv;

    /**
     * < 最大流通市值(千万元)
     **/
    private BigDecimal maxTradeMv;

    //近N天数据
    private Integer latelyDay;

    /**
     * 从什么时候开始取数 2024-01-01
     * 默认最近30天
     **/
    private String startDate;

    /**
     * 截止取数 2024-12-01
     * 默认最近30天
     **/
    private String endDate;

    private String currentDate;

    private Set<String> stockCodes;
    
    /**
     * 0-不持久，1-持久化,默认0
     **/
    private Integer hasPersistent;

    /**
     * 成交量(万手) >= n%
     **/
    private BigDecimal tradeVolume;

    /**
     * 成交额(千万元) >= n%
     **/
    private BigDecimal tradeAmount;

    /**
     * 当日涨跌幅度
     **/
    private BigDecimal minUpDown;

    /**
     * 当日涨跌幅度
     **/
    private BigDecimal maxUpDown;

    /**
     * 当日振幅 <= n%
     **/
    private BigDecimal amplitude;

    /**
     * 均线配置
     **/
    private SmaForm sma;

    public static void trans(PickStockQueryForm queryForm){
        queryForm.setCurrentDate(DateUtil.format(DateUtil.date(), DatePattern.NORM_DATE_FORMAT));
        if(StringUtils.isBlank(queryForm.getStartDate())){
            //往前推30天
            queryForm.setStartDate(DateUtil.format(
                    DateUtil.offsetDay(DateUtil.date(),-30), DatePattern.NORM_DATE_FORMAT));
        }
        if(Objects.nonNull(queryForm.getMinTradeMv())){
            queryForm.setMinTradeMv(queryForm.getMinTradeMv().multiply(new BigDecimal(10000000)));
        }
        if(Objects.nonNull(queryForm.getMaxTradeMv())){
            queryForm.setMaxTradeMv(queryForm.getMaxTradeMv().multiply(new BigDecimal(10000000)));
        }
        if(Objects.nonNull(queryForm.getTradeVolume())){
            queryForm.setTradeVolume(queryForm.getTradeVolume().multiply(new BigDecimal(10000)));
        }
        if(Objects.nonNull(queryForm.getTradeAmount())){
            queryForm.setTradeAmount(queryForm.getTradeAmount().multiply(new BigDecimal(10000000)));
        }
    }

    public static void main(String[] args) {
        PickStockQueryForm queryForm = new PickStockQueryForm();
        queryForm.setExchangeRate(BigDecimal.valueOf(3));
        queryForm.setLatelyDay(7);
        queryForm.setMinTradeMv(BigDecimal.valueOf(200)); //20亿
        queryForm.setMaxTradeMv(BigDecimal.valueOf(2000)); //200亿
        queryForm.setHasPersistent(0);
        if(Objects.nonNull(queryForm.getLatelyDay())){
            String endDate = DateUtil.format(DateUtil.date(), DatePattern.NORM_DATE_FORMAT.getPattern());
            Date start = DateUtil.offsetDay(DateUtil.date(),-queryForm.getLatelyDay());
            String startDate =DateUtil.format(start, DatePattern.NORM_DATE_FORMAT.getPattern());
            queryForm.setStartDate(startDate);
            queryForm.setEndDate(endDate);
        }
        SmaForm smaForm = new SmaForm();
        smaForm.setPeriod(new Integer[]{5,10,15});
        smaForm.setShortUpMid(true);
        smaForm.setMidUpLong(true);
        queryForm.setSma(smaForm);
        System.out.println(JSONObject.toJSONString(queryForm));
    }
}
